import n from "./frameworkManager";
import l from "./FileMgr";
const { ccclass, property } = cc._decorator;

@ccclass
export default class MapPath extends cc.Component {
    @property(cc.Node)
    aniNode = null;

    posArr = [];
    aniMoveArr = [];

    onLoad() {
        this.aniNode.getComponent(cc.Animation).play("travel");
        this.openSchedule();
    }

    finshEnvent(e) {
        n.log("动画完成帧事件", e);
        this.aniMoveArr.push(this.posArr);
        n.log("aniMoveArr", this.aniMoveArr);
        this.openSchedule();
        if (31 == e) {
            var t = JSON.stringify(this.aniMoveArr);
            n.log("保存中...\n", this.aniMoveArr);
            l.downloadFile(t, "aniPath.json", false);
            n.log("保存成功");
        }
    }

    openSchedule() {
        this.unscheduleAllCallbacks();
        this.posArr = [];
        this.schedule(() => {
            var t = {
                x: this.aniNode.x,
                y: this.aniNode.y
            };
            this.posArr.push(t);
        }, 0.05);
    }
}
